var HTTP_HOST = "http://127.0.0.1/";
var loginuser = null;
$.ajaxSettings.async = false;
$.get(HTTP_HOST+"api/Auth/getloginuser",function(res){
if(res.msg=='CODE_UNAUTHORIZED'){

window.location.href=HTTP_HOST+"/index.html";
}else{

loginuser = res.result;


$("#login").html(loginuser.displayname);
$("#login").attr("type",loginuser.type);
$("#user").html(loginuser.displayname);



}	

});

function getQueryString(name) { 
 var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); 
 var r = window.location.search.substr(1).match(reg); 
 if (r != null) return unescape(r[2]); return null; 
} 


function getQueryString2(key){
    var reg = new RegExp("(^|&)"+key+"=([^&]*)(&|$)");
    var result = window.location.search.substr(1).match(reg);
    return result?decodeURIComponent(result[2]):null;
  }


function getstatus(stat){
    var status=null;

    switch(stat){
        case 0:
            status="预审中";
            break;
        case 1:
            status="评审中";
            break;
        case -1:
            status="驳回";
            break;
        case 3:
            status = "已分配专家";
            break;
        case 4:
            status="业主复核中";
            break;
        case 5:
            status="专员复核中";
             break;
        case 6:
            status="定审中";
            break;
        case 7:
            status="已完结 ";
            break;

    }

    return status;
}


function getstat(status){
    var index = 0;
    switch(status){
        case 0:
            index=1;
            break;
        case 1:
            index = 2;
            break;
        case 3:
            index = 2;
            break;
        case 4:
            index=3;
            break;
        case 5:
            index=3;
            break;
        case 6:
            index=4;
            break;
        case 7:
            index=5;
            break;
        case -1:
            index=0;
            break;

    }
    return index;
}


function getlogname(v){
    var orga = null;
    if(v.isgroup == 1){
        orga = "专家小组意见";
    }else{
        if(v.usertype==4){
            orga = "专家";
        }else if(v.usertype == 5){
            orga = "机构";
        }else if(v.usertype == 2){
            orga = "业主复审";
        }else if(v.usertype == 6){
            orga = "评审专员";
        }else if(v.usertype ==3){
            orga="分管领导";
        }
    }

    return orga;
}

function getusertype(v){
    var orga = null;
    if(v == 0){
        orga = "委托机构";
    }else{
        if(v==2){
            orga = "业主";
        }else if(v == 3){
            orga = "分管领导";
        }else if(v == 4){
            orga = "评审专家";
        }else if(v == 5){
            orga = "评审机构";
        }else if(v ==6){
            orga="评审专员";
        }else if(v==1){
            orga="受理员";
        }
    }

    return orga;
}


function timestampToTime(timestamp) {
    var date = new Date(timestamp * 1000);
    var Y = date.getFullYear() + '-';
    var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
    var D = date.getDate() + ' ';
    var h = date.getHours() + ':';
    var m = date.getMinutes() + ':';
    var s = date.getSeconds();
    return Y+M+D;
}


function timestampToTime2(timestamp) {
    var date = new Date(timestamp * 1000);
    var Y = date.getFullYear() + '-';
    var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
    var D = date.getDate() + ' ';
    var h = date.getHours() + ':';
    var m = date.getMinutes() + ':';
    var s = date.getSeconds();
    return Y+M+D+h+m+s;
}


function fillsearch(){
  
   

    $.get("/api/Index/getlevels",function(res){

        var levels = res.result.level;
        var opt = "";
        opt+=` <option value="all">全部</option>`;
        $.each(levels,function(k,v){

            opt+=`<option value=`+v.level+`>`+v.level+`</option>`;
            
        });
        opt+=`</select>`;
        $("#level").html(opt);
        var opt_type = `<option value="1" selected = "selected" >全部</option>`;
       
        $.each(res.result.type,function(k,v){
            opt_type+=`<option value=`+v.name+`>`+v.name+`</option>`;
        });

        $("#pslb").html(opt_type);
        var industry = `<option value="1" selected = "selected" >全部</option>`;
    
        $.each(res.result.industry,function(k,v){
            industry+=`<option value=`+v.name+`>`+v.name+`</option>`;
        });


        $("#industry").html(industry);
    },'json');



    $("#owner").val(getQueryString2('owner'));
    $("#lxnumber").val(getQueryString2("lxnumber"));
     $("#name").val(getQueryString2("name"));
    $("#wtdw").val(getQueryString2("wtdw"));
    $("#bzjg").val(getQueryString2("bzjg"));
    $("#addtime").val(getQueryString2("addtime"));
    $("#wtdwlxr").val(getQueryString2("wtdwlxr"));
     $("#industry").val(getQueryString2("industry"));
     $("#pslb").val(getQueryString2("pslb"));

}






function filllogs(logs){
    var slyinfo = "";
    var slyidea = "";
    var leader = "";
    var expren = "";
    var jginfo = "";
    var owner = "";
    var oinfo="";
    var dszy = "";
    var groupidea="";
    var grouptime="";
    var fileleader = "";
    var groupleaderres = "";
            $.each(logs,function(k,v){
v.userid=v.displayname;
                
var res = "";
console.log(v.approveres);
console.log(v.approveres==1);
if(v.approveres == "1"){
res = `<span style="color:#0ff70f;">`+v.uuid+`</span>`;
}else{
    res = `<span style="color:red;">`+v.uuid+`</span>`;
}
                if(v.usertype == 1){
                    name="受理员";
                    var fileele = "";
                     if(Object.keys(v.file).length>0){
                        $.each(v.file,function(k,v){
                            fileele+=` <div class="add-item-files-span"><a href=`+v.path.replace(/uploadfiles/,"files")+`>`+v.name+`</div>`;
                        });

                }


                    
                    
                slyidea+=`<div class="scan-opinion-hd">
                <div class="tit" >`+v.userid+"编号："+res+`</div>
                <div class="txt">`+v.idea+`
                    <span style="float: right; font-size: 14px; font-weight: 10;">`+timestampToTime2(v.addtime)+`<span/>
                </div>
                <!--add-审核意见附件start-->
                <div class="add-item-files" style="width:1097px; margin: 0; ">
                    `+fileele+`
                
                </div>
                <!--add-审核意见附件 end-->
            </div>`;


                }else if(v.usertype == 3){
                    name="分管领导";
                    var fileele = "";

                    if(Object.keys(v.file).length>0){
                        $.each(v.file,function(k,v){
                            fileele+=` <div class="add-item-files-span"><a href=`+v.path.replace(/uploadfiles/,"files")+`>`+v.name+`</div>`;
                        });

                }

                    leader+=` <div class="scan-opinion-hd">
                    <div class="tit" >`+v.userid+"编号："+res+`</div>
                    <div class="txt">`+v.idea+`
                        <span style="float: right; font-size: 14px; font-weight: 10;">`+timestampToTime2(v.addtime)+`<span/>
                    </div>
                    <!--add-审核意见附件start-->
                    <div class="add-item-files" style="width:1097px; margin: 0; ">
                       `+fileele+`
                    </div>
                    <!--add-审核意见附件 end-->
                </div>`;

                }else if(v.usertype == 4){
                    name="专家个人";
                   
                    if(v.isgroup == 1){
                     groupidea=v.idea;
                     grouptime=v.addtime;
                     if(v.approveres == "1"){
                        groupleaderres = `<span style="color:#0ff70f;">`+v.uuid+`</span>`;
                        }else{
                            groupleaderres = `<span style="color:red;">`+v.uuid+`</span>`;
                        }

                     
                     if(Object.keys(v.file).length>0){
                        $.each(v.file,function(k,v){
                            fileleader+=` <div class="add-item-files-span"><a href=`+v.path.replace(/uploadfiles/,"files")+`>`+v.name+`</div>`;
                        });

                }


                    }else{

                            var filea = "";
                        if(Object.keys(v.file).length>0){
                            $.each(v.file,function(k,v){
                                filea+=` <div class="add-item-files-span"><a href=`+v.path.replace(/uploadfiles/,"files")+`>`+v.name+`</div>`;
                            });
    
                    }

        expren+=`<div class="scan-opinion-item clearfix">
        <span class="tip fl" style="width:400px;">`+v.userid+"编号："+res+`</span>
       `+v.idea+`
        <span style="float: right; font-size: 14px; font-weight: 10;">`+timestampToTime2(v.addtime)+`<span/>
    </div>
    <!--add-审核意见附件start-->
    <div class="add-item-files" style="width:1097px; margin: 0; ">
        `+filea+`
    </div>`;
                    }

                }else if(v.usertype == 5){
                    var fileele = "";

                    if(Object.keys(v.file).length>0){
                        $.each(v.file,function(k,v){
                            fileele+=` <div class="add-item-files-span"><a href=`+v.path.replace(/uploadfiles/,"files")+`>`+v.name+`</div>`;
                        });

                }
        jginfo+=`<div class="scan-opinion-hd">
        <div class="tit" style="width:240px;">`+v.userid+"编号："+res+`</div>
        <div class="txt">`+v.idea+`                  
            <span style="float: right; font-size: 14px; font-weight: 10;">`+timestampToTime2(v.addtime)+`<span/>
        </div>
        <!--add-审核意见附件start-->
        <div class="add-item-files" style="width:1097px; margin: 0; ">
            `+fileele+`
        </div>
        <!--add-审核意见附件 end-->
    </div>`;


        }else if(v.usertype == 2){

            var fileele = "";

            if(Object.keys(v.file).length>0){
                $.each(v.file,function(k,v){
                    fileele+=` <div class="add-item-files-span"><a href=`+v.path.replace(/uploadfiles/,"files")+`>`+v.name+`</div>`;
                });

        }
        name="业主";
        oinfo+=` <div class="scan-opinion-hd">
        <div class="tit" style="width:400px;">`+v.userid+"编号："+res+`</div>
        <div class="txt">`+v.idea+`
            <span style="float: right; font-size: 14px; font-weight: 10;">`+timestampToTime2(v.addtime)+`<span/>
        </div>
        <!--add-审核意见附件start-->
        <div class="add-item-files" style="width:1097px; margin: 0; ">
           `+fileele+`
        </div>
        <!--add-审核意见附件 end-->
    </div>`;


        }else if(v.usertype == 6){

            var fileele = "";

            if(Object.keys(v.file).length>0){
                $.each(v.file,function(k,v){
                    fileele+=` <div class="add-item-files-span"><a href=`+v.path.replace(/uploadfiles/,"files")+`>`+v.name+`</div>`;
                });

        }
                name="丁森专员";
                dszy+=`<div class="scan-opinion-hd">
                <div class="tit" style="width:400px;">`+v.userid+"编号："+res+`</div>
                <div class="txt">`+v.idea+`
                    <span style="float: right; font-size: 14px; font-weight: 10;">`+timestampToTime2(v.addtime)+`<span/>
                </div>
                <!--add-审核意见附件start-->
                <div class="add-item-files" style="width:1097px; margin: 0; ">
                    `+fileele+`
                </div>
                <!--add-审核意见附件 end-->
            </div>`;

        }

            });


            var slyinfo = `<div class="scan-main">
            <!--scan-box start-->
            <div class="scan-box">
                <div class="scan-box-tit">受理员意见</div>
                <div class="scan-opinion">
                    `+slyidea+`
                </div>
            </div>
            <!--scan-box end-->
        </div>`;

        var leaderinfo = `<div class="scan-main">
        <!--scan-box start-->
        <div class="scan-box">
            <div class="scan-box-tit">定审意见</div>
            <div class="scan-opinion">
                `+leader+`
            </div>
        </div>
        <!--scan-box end-->
    </div>`;

        var expreninfo = `<div class="scan-main">
        <!--scan-box start-->
        <div class="scan-box">
        <div class="scan-box-tit">专家审核意见</div>
        <div class="scan-opinion">
        `+
        expren
        +`
        </div>
        </div>
        <!--scan-box end-->
        </div>`;

        var expjginfo = `<div class="scan-main">
        <!--scan-box start-->
        <div class="scan-box">
            <div class="scan-box-tit">机构专家意见</div>
            <div class="scan-opinion">
                `+jginfo+`
            </div>
        </div>
        <!--scan-box end-->
    </div>`;

        var dszyinfo = ` <div class="scan-main">
        <!--scan-box start-->
        <div class="scan-box">
            <div class="scan-box-tit">专员意见</div>
            <div class="scan-opinion">
                `+dszy+`
            </div>
        </div>
        <!--scan-box end-->
    </div>`;


        var ownerinfo = `<div class="scan-main">
        <!--scan-box start-->
        <div class="scan-box">
            <div class="scan-box-tit">业主意见</div>
            <div class="scan-opinion">
                `+oinfo+`
            </div>
        </div>
        <!--scan-box end-->
    </div>`;



var expeople = ` <div class="scan-main">
<!--scan-box start-->
<div class="scan-box">
    <div class="scan-box-tit">个人专家意见</div>
    <div class="scan-opinion">
        <div class="scan-opinion-hd">
            <div class="tit" style="width:400px">专家小组意见`+groupleaderres+`</div>
            <div class="txt">`+groupidea+`
                <span style="float: right; font-size: 14px; font-weight: 10;">`+timestampToTime2(grouptime)+`<span/>
            </div>
             <!--add-审核意见附件start-->
            <div class="add-item-files" style="width:1097px; margin: 0; ">
                `+fileleader+`
            </div>
            <!--add-审核意见附件 end-->
        </div>
        `+expren+`
        <!--add-审核意见附件 end-->
    </div>
</div>
<!--scan-box end-->
</div>`;

  

    if(slyidea != ""){
    $("#reject").append(slyinfo);
    }

 


    if(expren != ""){
    $("#reject").append(expeople);
    }


    if(jginfo != ""){

    $("#reject").append(expjginfo);
    }

    if(oinfo != ""){

    $("#reject").append(ownerinfo);
    }



    if(dszy != ''){
        $("#reject").append(dszyinfo);

    }
    if(leader != ""){
        $("#reject").append(leaderinfo);
        }


}

function removefile(obj){
    console.log("das");

    $(obj).parent().remove();



}

